package com.hdd.fmh.common.config;


import com.hdd.fmh.common.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
* @Description:  拦截器 和  类的自动注入方法
 */
@Configuration
public class SysConfiguration implements WebMvcConfigurer {

	@Bean
	LoginInterceptor interceptor() {
		return new LoginInterceptor();
	}


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则 ， 先把所有路径都加入拦截， 再一个个排除
    	//不拦截 静态资源、swagger 等 登录相关
        registry.addInterceptor(interceptor())
				.excludePathPatterns("/swagger-ui.html",
						"/swagger-resources/**",
						"/error",
						"/webjars/**"
				).excludePathPatterns("/uploadFile").excludePathPatterns("/uploadMultipleFiles");
    }
	
	
	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }


}
